#include<stdio.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<fcntl.h>
#include<stdlib.h>
#include<unistd.h>

int main()
{
	int fd = open("c.txt",O_RDWR|O_CREAT|O_APPEND,0666);
	if(fd==-1){
		perror("open");
		return -1;
	}

	//获取标志
	int flags = fcntl(fd,F_GETFL);
	if(flags==-1){
		perror("fcntl");
		return -1;
	}
	printf("falgs = %d \n",flags);  //33794
	
	if(flags&O_RDWR){
		printf("O_RDWR\n");
	}

	if(flags&O_CREAT){
		printf("O_CREAT\n");
	}

	
	if(flags&O_APPEND){
		printf("O_APPEND\n");
	}

	//设置标志
	//flags &= ~O_RDWR;
	//flags |= O_RDONLY;
	flags &= ~O_APPEND;
	fcntl(fd,F_SETFL,flags);
	//获取标志
	flags = fcntl(fd,F_GETFL);
	if(flags==-1){
		perror("fcntl");
		return -1;
	}

	if(flags&O_RDONLY){
		printf("O_RDONLY\n");
	}
	
	if(flags&O_APPEND){
		printf("O_APPEND\n");
	}

	
	close(fd);

	return 0;
}